home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10576 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: amaryllisp1.appsig.com!user
  2. From: larry_kearney@appsig.com (Larry Kearney)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Another What does this do...
  5. Date: Mon, 18 Mar 1996 10:50:31 -0700
  6. Organization: Who ever said I was organized?
  7. Message-ID: <larry_kearney-1803961050310001@amaryllisp1.appsig.com>
  8. References: <4ijkrh$8t@apollo.isisnet.com>
  9. NNTP-Posting-Host: amaryllisp1.appsig.com
  10.  
  11. > Asside from never having programmed in C before, I figured I was doing
  12. > quite well until I came across the following statement:
  13. >         pb = (char *)&dop;
  14. > where pb and dop are defined as:
  15. >         char *pb;
  16. > and
  17. >         dop is structure DOP like this:
  18. >         typedef struct doc_prop
  19. >         {
  20. >             int xaPage;
  21. >               ...
  22. >             char flandscape;
  23. >         } DOP;
  24.  
  25. What they are doing is simply casting a pointer to the memory allocated to
  26. dop for the structure doc_prop (represented by taking the address of dop)
  27. into a pointer to a char. This is then assigned to pb which is a variable
  28. defined as a pointer to a char.
  29.  
  30. If you tried to do something like
  31.  
  32. pb = &dop
  33.  
  34. the compiler would complain because your are attempting to assign an
  35. incorrect type to pb. Casting the pointer as a char eliminates this
  36. complaint. I assume that they are attempting to access individual
  37. char-sized pieces of the structure through pb (for copying perhaps).
  38.  
  39. -- 
  40. Larry Kearney                   |   "You want fries with that?"
  41. Applied Signal Technology       |
  42. larry_kearney@appsig.com        |
  43.